function wxlogin() {
    var abcd = $("#gourl").val();
    var str = "<div class='headerTx'><section class='wx_login'> <a class='wxgba' href='javascript:void(0);' onclick='gb_wxlogin();'></a><iframe class='qq_iframe' src='" + domain + "/oauth/wechat/pclogin.php?tz=" + encodeURI(abcd) + "'></iframe></section></div>";
    $("body").append(str);
    $('.headerTx').fadeIn(300);
}

function gb_wxlogin() {
    $('.headerTx').remove().fadeOut(0);
}

function sx_wxlogin() {
    var aabbcc = $("#tzde").val();
    if (aabbcc) {
        window.location.href = "" + decodeURI(aabbcc);
    } else {
        location.href = "/";
    }
}

function sx_wxlogins(urls) {
    if (urls) {
        window.location.href = "" + decodeURI(urls);
    } else {
        location.href = "/";
    }
}

function login() {
    var etime = $("#time").val();
    var abdc = $("#tzde").val();
    $.post(domain + "/oauth/wechat/ajax.php", {
        enews: "login",
        etime: etime,
        tzde: encodeURI(abdc)
    }, function (data) {
        if (data == 'end') {
        }
        else {
            if (abdc) {
                parent.sx_wxlogins(abdc);
            } else {
                parent.sx_wxlogin();
            }
        }
    })
}

function wxsq() {
    var etime = $("#time").val(), openid = $("#openid").val(), username = $("#username").val(),
        userpic = $("#userpic").val(), address = $("#address").val(), gzzt = $("#gzzt").val(), abdc = $("#tzde").val();
    $.post(domain + "/oauth/wechat/ajax.php", {
        enews: "wxsq",
        etime: etime,
        openid: openid,
        username: username,
        userpic: userpic,
        address: address,
        gzzt: gzzt,
        tzde: encodeURI(abdc)
    }, function (data) {

        if (data == 'dberror') {
            $(".wxsq_title").text("").text("授权失败，请重新尝试!");
        }
        else if (data == 'endtime') {
            $(".wxsq_title").text("").text("二维码已过期，请重新获取!");
            $(".wxsq_btn").addClass('dn');
        }
        else if (data == 'islogin') {
            $(".wxsq_title").text("").text("二维码已失效，请重新获取!");
            $(".wxsq_btn").addClass('dn');
        }
        else {
            $(".wxsq_title").text("").text("授权成功，请关闭该页面!");
            $(".wxsq_btn").addClass('dn');
        }
    })
}

//判断网站是否在微信客户端打开
function isWeixin() {
    var ua = navigator.userAgent.toLowerCase();
    if (ua.match(/MicroMessenger/i) == "micromessenger") {
        return true;
    } else {
        return false;
    }
}

//判断网站是否在微信客户端打开
$(document).ready(function () {
    if (isWeixin()) {
        $('#wxlogin').attr('href', domain + '/oauth/wechat/').removeAttr("onclick");
    }
});